
var aa1 = document.getElementById("a1");
var aa2 = document.getElementById("a2");
var aa3 = document.getElementById("a3");
var bb1 = document.getElementById("b1");
var bb2 = document.getElementById("b2");
var bb3 = document.getElementById("b3");
var cc1 = document.getElementById("c1");
var cc2 = document.getElementById("c2");
var cc3 = document.getElementById("c3");

aa1.onmouseover = hint;
aa2.onmouseover = hint;
aa3.onmouseover = hint;
bb1.onmouseover = hint;
bb2.onmouseover = hint;
bb3.onmouseover = hint;
cc1.onmouseover = hint;
cc2.onmouseover = hint;
cc3.onmouseover = hint;

var show = document.getElementById("show");
var refurbish = document.getElementById("refurbish");
refurbish.onclick = function()
{
    location.reload();
}

async function buOnclick()
{
    if(a1.value==""||a2.value==""||a3.value=="")
    {
        alert("请输入完整！");
        return;
    }
    if(b1.value==""||b2.value==""||b3.value=="")
    {
        alert("请输入完整！");
        return;
    }
    if(c1.value==""||c2.value==""||c3.value=="")
    {
        alert("请输入完整！");
        return;
    }
    var x1 = aa1.value*1;
    var y1 = aa2.value*1;
    var z1 = aa3.value*1;
    var x2 = bb1.value*1;
    var y2 = bb2.value*1;
    var z2 = bb3.value*1;
    var x3 = cc1.value*1;
    var y3 = cc2.value*1;
    var z3 = cc3.value*1;

    try{
        x1 = eval(aa1.value);
        y1 = eval(aa2.value);
        z1 = eval(aa3.value);
        x2 = eval(bb1.value);
        y2 = eval(bb2.value);
        z2 = eval(bb3.value);
        x3 = eval(cc1.value);
        y3 = eval(cc2.value);
        z3 = eval(cc3.value);
    }catch(error){
        alert("输入格式不正确，请重新输入！");
        return;
    }
    var x11 = x1+x2+x3;
    var y22 = y1+y2+y3;
    var z33 = z1+z2+z3;
    var bb = Math.max(Math.abs(x1), Math.abs(x2), Math.abs(x3),Math.abs(x11),
                    Math.abs(y1), Math.abs(y2), Math.abs(y3),Math.abs(y22),
                    Math.abs(z1),Math.abs(z2),Math.abs(z3),Math.abs(z33));

    
    context.lineWidth = 3;
    checkAxes(mycanvas,context,bb,bb,3);
    await drow3DVector(context,x1,y1,z1,false);
    addFont_3D(context,"a",x1,y1,z1,"red","bold italic 20pt Times new roman");
    await Sleep(2000);
    await drow3DVector(context,x2,y2,z2,false);
    addFont_3D(context,"b",x2,y2,z2,"red","bold italic 20pt Times new roman");
    await Sleep(2000);
    await drow3DVector(context,x3,y3,z3,false);
    addFont_3D(context,"c",x3,y3,z3,"red","bold italic 20pt Times new roman");
    await Sleep(3000);
    
    drowCubeXYZ(context,x1,y1,z1,x2,y2,z2,x3,y3,z3);
    addFont_3D(context,"D",x3+x1+x2,y3+y2+y1,z3+z1+z2,"red","bold italic 20pt Times new roman");
    
    addFont_3D(context,"a",x1,y1,z1,"red","bold italic 20pt Times new roman");
    addFont_3D(context,"b",x2,y2,z2,"red","bold italic 20pt Times new roman");
    addFont_3D(context,"c",x3,y3,z3,"red","bold italic 20pt Times new roman");
}


drow3DAxes(context);
show.addEventListener('click',buOnclick);